/**
 * Copyright (C) 2015 Baidu, Inc. All Rights Reserved.
 */
package map.android.baidu.carpool.utils;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.baidu.components.api.extra.APIProxy;

/**
 * @Author chenlei18
 * @Description 操作软键盘的开启和关闭
 * @CreateTime 2015-3-12 下午10:34:51
 */
public class HelpUtils {

    public static void closeSoftKeyboard(View whereEditText) {
        if (whereEditText == null) {
            return;
        }

        try {
            InputMethodManager imm =
                    (InputMethodManager) APIProxy.res().getBaseActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(whereEditText.getWindowToken(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void showSoftKeyboard(View whereEditText) {
        if (whereEditText == null) {
            return;
        }
        try {
            whereEditText.requestFocus();
            InputMethodManager imm =
                    (InputMethodManager) APIProxy.res().getBaseActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(whereEditText, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
